import {
	callFunc
} from "../../request.js"
import db from '@/js_sdk/uni-clientDB/index.js'
const dbCmd = db.command

//获取商品评价
export function getEvaluationPage({
	scriptId,
	goodsId,
	roomId,
	pageNum = 1,
	pageSize = 10,
	showLoading = true
}) {
	return callFunc({
		showLoading,
		funcName: "uni-admin",
		data: {
			action: "goods/getEvaluationPage",
			data: {
				scriptId,
				goodsId,
				roomId,
				pageNum,
				pageSize
			}
		}
	});
}

//获取商品列表
//order: {'sell_count': 'desc', 'hit_count': 'asc'}
export function getGoodsList({
	city,
	pageNum,
	pageSize,
	keyword,
	filter,
	order,
	userLocation,
	showLoading = true
}) {
	return callFunc({
		showLoading,
		funcName: "uni-admin",
		data: {
			action: "goods/getGoodsList",
			data: {
				city,
				pageNum,
				pageSize,
				keyword,
				filter,
				order,
				userLocation,
				token: uni.getStorageSync("uni_id_token")
			}
		}
	});
}

//获取商品详情
export function getGoodsDetail({
	id,
	userLocation,
	showLoading = true
}) {
	return callFunc({
		showLoading,
		funcName: 'uni-admin',
		data: {
			action: 'goods/getGoodsDetail',
			data: {
				id,
				userLocation,
				token: uni.getStorageSync("uni_id_token")
			}
		}
	})
}

export function getCategories(options) {
	let opt = options ? Object.assign({}, options) : {};
	opt.funcName = "category";
	opt.data = {
		command: db.collection("t3ds-mall-categories").where({
			_id: dbCmd.exists(true)
		}).get()
	};
	return callFunc(opt);
}

// 获取城市
export function getRegionList(data, showLoading = true) {
	return callFunc({
		showLoading,
		funcName: "uni-admin",
		data: {
			action: 'search/getCityList',
			data: data
		}
	})
}